package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */


@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService iReservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Long userId = UserThreadLocal.getUserId();
        System.out.println("------" + userId);
        return R.ok(0);
    }
    @GetMapping("/page")
    @ApiOperation("分页查询预约信息")
    public TableDataInfo<List<Reservation>> getReservationPage(Reservation  reservation){
        startPage();
        List<Reservation> list = iReservationService.selectReservationPage(reservation);
        return getDataTable(list);
    }
    /**
     * 新增预约信息
     */
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增预约信息")
    public AjaxResult add(@ApiParam(value = "预约信息实体", required = true) @RequestBody Reservation reservation)
    {
        return toAjax(iReservationService.insertReservation(reservation));
    }
    /**
     * 查询取消预约次数
     * */
    @GetMapping("/cancel-count")
    @ApiOperation("查询取消预约次数")
    public R<Integer> getCancelCount() {
        Long count = iReservationService.selectReservationCount();
        return R.ok(count.intValue());
    }
    /**
     * 取消预约
     */
    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public AjaxResult cancel(@ApiParam(value = "预约ID", required = true) @PathVariable Long id)
    {
        iReservationService.updateReservationStatus(id);
        return success();
    }
}
